package com.dsideal.cloud.cas.client.utils;

import com.dsideal.cloud.auth.common.util.jwt.IJWTInfo;
import com.dsideal.cloud.common.entity.Roles;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * 用户信息token封装类
 * @author suny
 */
public class JWTInfoForCas implements Serializable, IJWTInfo {
    private String username;
    private String userId;
    private String name;
    private String ua;
    // 资源
    private Set<String> authorities;
    // 角色
    private List<Roles> roles;

    //单位id
    private String bureauId;

    public JWTInfoForCas() {

    }

    public JWTInfoForCas(String username, String userId, String name, String ua) {
        this(username, userId, name, ua, null, null, null);
    }

    public JWTInfoForCas(String username, String userId, String name, String ua, List<Roles> roles, String bureauId) {
        this(username, userId, name, ua, null, roles, bureauId);
    }


    public JWTInfoForCas(String username, String userId, String name, String ua, Set<String> authorities, List<Roles> roles) {
        this(username, userId, name, ua, authorities, roles, null);
    }

    public JWTInfoForCas(String username, String userId, String name, String ua, Set<String> authorities, List<Roles> roles, String bureauId) {
        this.username = username;
        this.userId = userId;
        this.name = name;
        this.ua = ua;
        this.authorities = authorities;
        this.roles = roles;
        this.bureauId = bureauId;
    }

    @Override
    public String getUniqueName() {
        return userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public String getId() {
        return userId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public Set<String> getAuthorities() {
        return this.authorities;
    }

    public void setAuthorities(Set<String> authorities) {
        this.authorities = authorities;
    }

    @Override
    public List<Roles> getRoles() {
        return roles;
    }

    public void setRoles(List<Roles> roles) {
        this.roles = roles;
    }

    public String getUa() {
        return ua;
    }

    public void setUa(String ua) {
        this.ua = ua;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        JWTInfoForCas jwtInfoForCas = (JWTInfoForCas) o;

        if (username != null ? !username.equals(jwtInfoForCas.username) : jwtInfoForCas.username != null) {
            return false;
        }
        return userId != null ? userId.equals(jwtInfoForCas.userId) : jwtInfoForCas.userId == null;

    }

    @Override
    public int hashCode() {
        int result = username != null ? username.hashCode() : 0;
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        return result;
    }
    @Override
    public String getBureauId() {
        return bureauId;
    }

    public void setBureauId(String bureauId) {
        this.bureauId = bureauId;
    }
}
